using System;
using System.Collections.Generic;
using Voodoo.Sauce.Internal;
using Voodoo.Sauce.Internal.IntegrationCheck;

namespace Voodoo.Sauce.Core
{
	internal class IAPCore : IModule
	{
		private const string TAG = "IAPCore";

		protected readonly PurchaseDelegateList purchaseDelegateList = new PurchaseDelegateList();

		private bool _isInitCalled;

		internal virtual bool IsInstalled()
		{
			return false;
		}

		internal virtual List<ProductReceivedInfo> GetProducts()
		{
			return null;
		}

		internal virtual ProductReceivedInfo GetProductWithId(string productId)
		{
			return null;
		}

		public virtual List<IntegrationCheckMessage> IntegrationCheck(VoodooSettings settings)
		{
			return null;
		}

		internal virtual void Initialize(VoodooSettings voodooSettings)
		{
			_isInitCalled = true;
		}

		internal virtual void RefreshIapSubscriptionInfo()
		{
		}

		internal virtual void AddIapPurchaseDelegate(IPurchaseDelegateWithInfo purchaseDelegate)
		{
			purchaseDelegateList.Add(purchaseDelegate);
			if (_isInitCalled)
			{
				purchaseDelegate.OnInitializeFailure(VoodooInitializationFailureReason.IAPModuleNotInstalled);
			}
		}

		internal void RemoveIapPurchaseDelegate(IPurchaseDelegateWithInfo purchaseDelegate)
		{
			purchaseDelegateList.Remove(purchaseDelegate);
		}

		internal virtual void BuyIAPProduct(string productId, IPurchaseDelegateWithInfo caller, IPurchaseValidator customPurchaseValidator)
		{
		}

		internal virtual void RestoreIAPProduct(Action<RestorePurchasesResult> callback)
		{
			callback(RestorePurchasesResult.IAPModuleNotInstalled);
		}

		internal virtual string GetLocalizedProductPrice(string productId)
		{
			return string.Empty;
		}

		internal virtual bool IsSubscribedProduct(string productId)
		{
			return false;
		}

		internal virtual bool IsSubscribedProduct()
		{
			return false;
		}

		internal virtual SubscriptionInfoContainer GetSubscriptionDetails(string productId)
		{
			return null;
		}

		internal virtual LocalizedPriceInfo GetLocalizedProductPriceInfo(string productId)
		{
			VoodooLog.LogWarning(Module.IAP, "IAPCore", "You can't get the price of a product because the IAP module isn't installed.");
			return null;
		}
	}
}
